package com.app.oasystem.controller;


import com.app.oasystem.dto.ActionResult;
import com.app.oasystem.dto.PageGridDto;
import com.app.oasystem.entity.Leaves;
import com.app.oasystem.service.impl.LeavesServiceImpl;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 86+
 * @data 2021-04-13
 */

@RestController
@RequestMapping("/leaves")
public class LeavesController {
    @Resource
    private LeavesServiceImpl leavesService;

    /**
     * 分页获取Leaves列表
     */
    @PostMapping("/all")
    public Object getLeavesList(@RequestBody PageGridDto pageGridDto) {
        return leavesService.getLeavesList(pageGridDto);
    }

    /**
     * 根据id获取Leaves信息
     */
    @GetMapping("/{id}")
    public Object getLeavesInfoById(@PathVariable("id") Integer id) {
        return new ActionResult(leavesService.getLeavesInfoById(id));
    }
    /**
     * 同意 /  拒绝
     */
    @GetMapping("/{id}/{leaveId}")
    public Object approval(@PathVariable("id") Integer id,@PathVariable("leaveId") Integer leaveId) {
        return new ActionResult(leavesService.approval(id,leaveId));
    }


    /**
     * 根据名称获取Leaves信息
     */
    @GetMapping("/n")
    public Object getLeavesInfoById(@RequestParam("name") String name) {
        return new ActionResult(leavesService.getLeavesInfoByName(name));
    }

    /**
     * 新增Leaves
     */
    @PostMapping("/add")
    public Object insertLeaves(@RequestBody Leaves leaves) {
        return new ActionResult(leavesService.insertLeaves(leaves));
    }

    /**
     * 更新Leaves
     */
    @PostMapping("/update")
    public Object updateLeaves(@RequestBody Leaves leaves) {
        return new ActionResult(leavesService.updateLeaves(leaves));
    }

    /**
     * 根据id删除Leaves
     */
    @DeleteMapping("/{id}")
    public Object delLeaves(@PathVariable("id") Integer id) {
        return new ActionResult(leavesService.deleteLeaves(new Leaves().setId(id)));
    }
}

